# Unix Makefile for qhull and rbox
#
#       see README.txt
#       the Unix distribution contains a configure Makefile
#       
#       make           to produce qhull qconvex qdelaunay qhalf qvoronoi rbox
#       make qvoronoi  to produce qvoronoi (etc.)
#       make qhullx    to produce qhull qconvex etc.  w/o using libqhull.a
#       make doc       to print documentation
#       make install   to copy qhull, rbox, qhull.1, rbox.1 to BINDIR, MANDIR
#       make new       to rebuild qhull and rbox from source
#
#       make printall  to print all files
#       make user_eg   to produce user_eg
#       make user_eg2  to produce user_eg2
#       make clean     to remove object files and core
#       make cleanall  to remove all generated files
#
#       PRINTMAN --    command for printing manual pages
#       PRINTC --      command for printing C files
#       BINDIR --      directory where to copy executables
#       MANDIR --      directory where to copy manual pages
#       CC --          ANSI C or C++ compiler
#       CCOPTS1 -      options used to compile .c files
#       CCOPTS2 --     options used to link .o files
#
#       CFILES --      .c files for printing
#       HFILES --      .h files for printing
#       DFILES --       documentation files
#       MFILES --      man pages and html files
#       TFILES --      .txt versions of html html files
#       FILES --       all other files
#       OBJS --        specifies the object files of libqhull.a
#
# Do not replace tabs with spaces.  Needed by 'make' for build rules

BINDIR	= /usr/local/bin
MANDIR	= /usr/local/man/man1

# if you do not have enscript, try a2ps or just use lpr.  The files are text.
PRINTMAN = enscript -2rl
PRINTC = enscript -2r
# PRINTMAN = lpr
# PRINTC = lpr

#for Gnu's gcc compiler -O2 for optimization, -g for debugging, -Wall for check
#   -fno-strict-aliasing not needed for gcc 4.4+ (segfault in qset.c)
CC  = gcc
CCOPTS1 = -O2 -ansi -fno-strict-aliasing  
#COPTS1 = -g -ggdb  -O -fno-inline -gfull

# for Sun's cc compiler, -fast or O2 for optimization, -g for debugging, -Xc for ANSI
#CC = cc
#CCOPTS1 = -Xc -v -fast

# for Silicon Graphics cc compiler, -O2 for optimization, -g for debugging
#CC = cc
#CCOPTS1 = -ansi -O2

# for Next cc compiler with fat executable
#CC = cc
#CCOPTS1 = -ansi -O2 -arch m68k -arch i386 -arch hppa

# for loader, ld
CCOPTS2 = $(CCOPTS1)

# OBJS ordered by frequency of execution with small files at end.  Better locality.
OBJS = rboxlib.o user.o global.o stat.o io.o geom2.o poly2.o merge.o \
       libqhull.o geom.o poly.o qset.o mem.o usermem.o userprintf.o random.o

# CFILES ordered alphabetically after libqhull.c 
#CFILES= unix.c libqhull.c geom.c geom2.c global.c io.c mem.c merge.c poly.c \
		poly2.c random.c qset.c stat.c user.c qconvex.c qdelaun.c qhalf.c qvoronoi.c usermem.c userprintf.c rboxlib.c
CFILES= unix.c libqhull.c geom.c geom2.c global.c io.c mem.c merge.c poly.c \
		poly2.c random.c qset.c stat.c user.c qconvex.c qdelaun.c qhalf.c qvoronoi.c usermem.c userprintf.c
HFILES= user.h libqhull.h qhull_a.h geom.h io.h mem.h merge.h poly.h random.h qset.h stat.h
TXTFILES= ../Announce.txt ../REGISTER.txt ../COPYING.txt ../README.txt Changes.txt
DOCFILES= ../html/rbox.txt ../html/qhull.txt
#FILES=	Makefile rbox.c user_eg.c ../eg/q_test ../eg/q_egtest ../eg/q_eg
FILES=	Makefile 
HTMFILES= qhull.man rbox.man qh-code.htm qh-optg.htm qh-optt.htm qh-optp.htm \
		index.htm qh-quick.htm qh-impre.htm qh-eg.htm \
		qh-optc.htm qh-opto.htm qh-optf.htm qh-optq.htm \
		qh-c.htm qh-faq.htm qhull.htm qconvex.htm qdelaun.htm \
		qh-geom.htm qh-globa.htm qh-io.htm qh-mem.htm qh-merge.htm \
		qh-poly.htm qh-qhull.htm qh-set.htm qh-stat.htm qh-user.htm \
		qdelau_f.htm qhalf.htm qvoronoi.htm qvoron_f.htm rbox.htm 

#all: rbox qconvex qdelaunay qhalf qvoronoi qhull
all: libqhull.a

unix.o:	    libqhull.h user.h mem.h
qconvex.o:  libqhull.h user.h mem.h
qdelaun.o:  libqhull.h user.h mem.h
qhalf.o:    libqhull.h user.h mem.h
qvoronoi.o: libqhull.h user.h mem.h
libqhull.o: $(HFILES)
geom.o:	    $(HFILES)
geom2.o:    $(HFILES)
global.o:   $(HFILES)
io.o:	    $(HFILES)
mem.o:	    mem.h 
merge.o:    $(HFILES)
poly.o:	    $(HFILES)
poly2.o:    $(HFILES)
random.o:   libqhull.h random.h
qset.o:	    qset.h mem.h 
stat.o:	    $(HFILES)
user.o:	    $(HFILES)

.c.o:
	$(CC) -c $(CCOPTS1) $<

clean:
	rm -f *.o ../core qconvex qdelaunay qhalf qvoronoi qhull libqhull.a \
              *.exe

cleanall: clean
	rm -f *~ ../rbox ../qhull ../qhalf ../qconvex ../qdelaunay ../qhalf\
		../qvoronoi ../user_eg ../user_eg2 ../*.exe >/dev/null

doc: 
	$(PRINTMAN) $(TXTFILES) $(DOCFILES)

install:  
	cp ../qconvex $(BINDIR)/qconvex
	cp ../qdelaunay $(BINDIR)/qdelaunay
	cp ../qhalf $(BINDIR)/qhalf
	cp ../qhull $(BINDIR)/qhull
	cp ../qvoronoi $(BINDIR)/qvoronoi
	cp ../rbox $(BINDIR)/rbox
	cp ../html/qhull.man $(MANDIR)/qhull.1
	cp ../html/rbox.man $(MANDIR)/rbox.1

new:	cleanall all

printall: doc printh printc printf

printh:
	$(PRINTC) $(HFILES)

printc:
	$(PRINTC) $(CFILES)

printf:
	$(PRINTC) $(FILES) 

libqhull.a: $(OBJS)
	@echo if 'ar' or 'ranlib' fails, try 'make qhullx'
	ar -r libqhull.a $(OBJS)
	@echo the next line may need to be removed.
	-test -x /bin/ranlib -o -x /usr/bin/ranlib && ranlib libqhull.a

# don't use ../qconvex.	 Does not work on Red Hat Linux
qconvex: qconvex.o libqhull.a
	$(CC) -o qconvex $(CCOPTS2) qconvex.o -L. -lqhull -lm 
	cp qconvex ..

qdelaunay: qdelaun.o libqhull.a
	$(CC) -o qdelaunay $(CCOPTS2) qdelaun.o -L. -lqhull -lm 
	cp qdelaunay ..

qhalf: qhalf.o libqhull.a
	$(CC) -o qhalf $(CCOPTS2) qhalf.o -L. -lqhull -lm 
	cp qhalf ..

qvoronoi: qvoronoi.o libqhull.a
	$(CC) -o qvoronoi $(CCOPTS2) qvoronoi.o -L. -lqhull -lm 
	cp qvoronoi ..

qhull: libqhull.a
	$(CC) -o qhull $(CCOPTS2) unix.o -L. -lqhull -lm 
	cp qhull ..
	-chmod +x ../eg/q_test ../eg/q_eg ../eg/q_egtest
	-cd ..; ./rbox D4 | ./qhull

# compile qhull without using libqhull.a
qhullx: qconvex.o qdelaun.o qhalf.o qvoronoi.o unix.o rbox.o $(OBJS)
	$(CC) -o qconvex $(CCOPTS2) qconvex.o $(OBJS) -lm 
	$(CC) -o qdelaunay $(CCOPTS2) qdelaun.o $(OBJS) -lm 
	$(CC) -o qhalf $(CCOPTS2) qhalf.o $(OBJS) -lm 
	$(CC) -o qvoronoi $(CCOPTS2) qvoronoi.o $(OBJS) -lm 
	$(CC) -o qhull $(CCOPTS2) unix.o $(OBJS) -lm 
	$(CC) -o rbox $(CCOPTS2) rbox.o $(OBJS) -lm 
	cp qconvex qdelaunay qhalf qvoronoi qhull rbox ..
	-chmod +x ../eg/q_test ../eg/q_eg ../eg/q_egtest
	-cd ..; ./rbox D4 | ./qhull

rbox: rbox.o libqhull.a
	$(CC) -o rbox rbox.o -L. -lqhull $(CCOPTS2) -lm
	cp rbox ..

user_eg: user_eg.o libqhull.a 
	$(CC)  -o user_eg $(CCOPTS2) user_eg.o	-L. -lqhull -lm 
	cp user_eg ..

user_eg2: user_eg2.o libqhull.a 
	$(CC)  -o user_eg2 $(CCOPTS2) user_eg2.o  -L. -lqhull -lm 
	cp user_eg2 ..

# end of Makefile
